{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-10-23T09:04:35.720002100Z",
     "start_time": "2024-10-23T09:04:35.701686Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "asdfghjkl\n",
      "8888888888888\n",
      "李丽老师真棒(๑•̀ㅂ•́)و✧\n",
      "\n",
      "asdfghjkl\n",
      "\n",
      "8888888888888\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "\n",
    "#模拟键盘输入\n",
    "# str =sys.stdin.readline()\n",
    "# print(str)\n",
    "# sys.stdout.write('hello \\n')\n",
    "# print(\"wordl\")\n",
    "\n",
    "file=open(\"file/a.txt\",\"r\",encoding=\"utf-8\",buffering=1)#utf8 中午跟支付\n",
    "print(file.read())\n",
    "file.close()\n",
    "print()\n",
    "with open(\"file/a.txt\",\"r\",encoding=\"utf-8\") as file:\n",
    "    # print(file.read())\n",
    "    print(file.readline())\n",
    "    #读取换行符  换行\n",
    "    print(file.readline())\n",
    "# print(file.readlines())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "I/O operation on closed file.",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mValueError\u001B[0m                                Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[9], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m \u001B[38;5;28mprint\u001B[39m(file\u001B[38;5;241m.\u001B[39mreadlines())\n",
      "\u001B[1;31mValueError\u001B[0m: I/O operation on closed file."
     ]
    }
   ],
   "source": [
    "str =\"here are you?\"\n",
    "with open('file/a.txt',mode='w',encoding='utf-8') as file:\n",
    "    size=file.write(str)\n",
    "    print(size)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-10-23T08:59:41.657915800Z",
     "start_time": "2024-10-23T08:59:40.728856300Z"
    }
   },
   "id": "53ab4dcc763f25d4"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
